package com.futures.investm.activity;

import android.os.Bundle;

import com.futures.investm.R;
import com.futures.investm.adapter.MessageAdapter;
import com.futures.investm.constant.BussConstant;
import com.aries.ui.view.title.TitleBarView;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseRefreshLoadActivity;

public class MsgActivity extends BaseRefreshLoadActivity<AVObject> {


    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("我的通知")
                .setStatusBarLightMode(false);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_msg;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
    }


    @Override
    public BaseQuickAdapter<AVObject, BaseViewHolder> getAdapter() {
        return new MessageAdapter();
    }

    @Override
    public void loadData(int page) {
        AVQuery<AVObject> query = new AVQuery<>(BussConstant.TABLE_MESSAGE);
        query.setLimit(10);
        query.setSkip(page * 10);
        query.orderByDescending("createdAt");
        query.findInBackground(new FindCallback<AVObject>() {
            @Override
            public void done(List<AVObject> list, AVException e) {
                // list 是一个 AVObject 的 List
                // list 指的就是所有包含当前 tag 的 TodoFolder
                if (e == null) {
                    FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), list, null);
                } else {
                    FastManager.getInstance().getHttpRequestControl().httpRequestError(getIHttpRequestControl(), e.getCode() + "", e.getMessage());
                }

            }
        });
    }
}
